package com.unicom.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.unicom.mapper.ItemsMapper;
import com.unicom.model.Items;
import com.unicom.service.ItemsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ItemsServiceImpl implements ItemsService {

	@Autowired
	private ItemsMapper itemsMapper;

	@Override
	public List<Items> getall() {
		List<Items> items = itemsMapper.selectByExample(null);
		return items;
	}

	@Override
	public List<Items> getall(int page,int rows) {

		PageHelper.startPage(page, rows);
		List<Items> items = itemsMapper.selectByExample(null);
		PageInfo<Items> pageInfo = new PageInfo<>(items);
		System.out.println(pageInfo);
		return items;
	}

	@Override
	public void add(Items items) {
		itemsMapper.insert(items);
	}

	@Override
	public Items get(int id) {
		return itemsMapper.get(id);
	}

	@Override
	@Transactional
	public void delete(int id) {
		itemsMapper.deleteByPrimaryKey(id);
	}

	@Override
	public void update(Items item) {
		itemsMapper.updateByPrimaryKeySelective(item);
	}


}
